<?php

session_start();
if (!empty($_SESSION['username'])) {
$conn_str = 'host=dbsrv1.cdf.toronto.edu dbname=csc309g23 user=csc309g23 password=ipheid5h';
$conn = pg_connect($conn_str);

$query = 'SELECT * FROM wall WHERE postid=' . $_GET['postID'] ;
$current_postid = pg_query($conn, $query);
if (pg_num_rows($current_postid) > 0) {
  
  $query = 'DELETE FROM wall WHERE postid=' . $_GET['postID'] ;  
  pg_query($conn, $query);
}

header('Location: ' . $_SERVER['HTTP_REFERER']);
} else {
header('Location: /');
}
?>
